package com.fox.imagedb.model;

import java.io.File;

import com.fox.imagedb.util.ImageFilter;

public class FileExplorer {

	private static ImageFilter IMAGE_FILTER = new ImageFilter();

	private File workingDirectory;

	private File[] images;

	private int imageIndex = 0;

	public File getWorkingDirectory() {
		return workingDirectory;
	}

	public File previousImage() {
		imageIndex--;
		if (imageIndex < 0) {
			imageIndex = images.length - 1;
		}
		return images[imageIndex];
	}

	public File nextImage() {
		imageIndex++;
		if (imageIndex >= images.length) {
			imageIndex = 0;
		}
		return images[imageIndex];
	}

	public File getCurrentImage() {
		return images[imageIndex];
	}

	public File updateWorkingDirectory(File workingDirectory) {
		this.workingDirectory = workingDirectory;
		this.images = workingDirectory.listFiles(IMAGE_FILTER);
		imageIndex = 0;
		return images[imageIndex];
	}

}
